package com.mach.platform.service;

import com.mach.platform.utils.CacheUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CacheServiceImpl {


    /**
     * 保存缓存数据
     * @param key
     * @param value
     */
    public void putCache(String key, Object value) {
        CacheUtils.guavaCacheFactory.put(key, value);
    }


    /**
     * 获取缓存数据
     * @param key
     * @return
     */
    public Object getCache(String key) {
        return CacheUtils.guavaCacheFactory.getIfPresent(key);
    }


    /**
     * 清除一个缓存
     * @param key
     */
    public void removeCache(String key) {
        CacheUtils.guavaCacheFactory.invalidate(key);
    }


    /**
     * 清除多个缓存
     * @param keys 缓存key的集合
     */
    public void removeCaches(List<String> keys) {
        CacheUtils.guavaCacheFactory.invalidateAll(keys);
    }


    /**
     * 清除所有缓存
     */
    public void removeAllCache() {
        CacheUtils.guavaCacheFactory.invalidateAll();
    }


}
